/**
 * @param {number} size
 */
 var Bitset = function(size) {
  this.bit = new Array(size).fill(0)
  this.rev = new Array(size).fill(1)
  this.oneCnt = 0
  this.size = size
};

/** 
 * @param {number} idx
 * @return {void}
 */
Bitset.prototype.fix = function(idx) {
  if(this.bit[idx] === 0){
    this.oneCnt++
  }
  this.bit[idx] = 1
  this.rev[idx] = 0
};

/** 
 * @param {number} idx
 * @return {void}
 */
Bitset.prototype.unfix = function(idx) {
  if(this.bit[idx]){
    this.oneCnt--
  }
  this.bit[idx] = 0
  this.rev[idx] = 1
};

/**
 * @return {void}
 */
Bitset.prototype.flip = function() {
  const temp = [...this.bit]
  this.bit = this.rev
  this.rev = temp
  this.oneCnt = this.size - this.oneCnt
};

/**
 * @return {boolean}
 */
Bitset.prototype.all = function() {
  return this.oneCnt === this.size
};

/**
 * @return {boolean}
 */
Bitset.prototype.one = function() {
  return this.oneCnt > 0
};

/**
 * @return {number}
 */
Bitset.prototype.count = function() {
  return this.oneCnt
};

/**
 * @return {string}
 */
Bitset.prototype.toString = function() {
  return this.bit.join('')
};

/**
 * Your Bitset object will be instantiated and called as such:
 * var obj = new Bitset(size)
 * obj.fix(idx)
 * obj.unfix(idx)
 * obj.flip()
 * var param_4 = obj.all()
 * var param_5 = obj.one()
 * var param_6 = obj.count()
 * var param_7 = obj.toString()
 */